package com.hu.zhcc.shiro.controller;

import com.hu.zhcc.shiro.entity.tj.*;
import com.hu.zhcc.shiro.service.TJ_TMemberService;
import com.hu.zhcc.shiro.service.Tj_TBodyTypeService;
import com.hu.zhcc.shiro.service.Tj_TQuestionnaireAnswerService;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/tjtbodyType")
public class TjTbodyTypeController {
    @Autowired
    private Tj_TBodyTypeService tj_tBodyTypeService;//体质类型表
    @Autowired
    private TJ_TMemberService tjTMemberService;//会员表
    @Autowired
    private Tj_TQuestionnaireAnswerService tjTQuestionnaireAnswerService;//答案表
    //连接体质类型表会员表查询
    @GetMapping("/queryTbody")
    public List<TBodyType> queryTbody(){
      return  tj_tBodyTypeService.queryType();
    }

    //根据会员身份证查询
    @GetMapping("/{idCard}")
    public VipdaTj queryByidCard(@PathVariable("idCard") String idCard){
        TMember tMember = tjTMemberService.queryByIsCard(idCard);
        VipdaTj vipdaTj=new VipdaTj();
        vipdaTj.setMember(tMember);
        return vipdaTj;
    }
    //插入数据
    @PostMapping("/{sum}/{sum2}/{sum3}/{id}")
    public int addType(@PathVariable("sum") Integer sum,@PathVariable("sum2") Integer sum2,@PathVariable("sum3")Integer sum3,@PathVariable("id") Integer id){
//        TQuestionBank tQuestionBank=new TQuestionBank();
        TQuestionnaireAnswer tQuestionnaireAnswer=new TQuestionnaireAnswer();
        tQuestionnaireAnswer.settMemberId(id);
        TBodyType tBodyType = new TBodyType();
        if(sum>=10){
            tBodyType.settQiAsthenia(0);
        }else {
            tBodyType.settQiAsthenia(1);
        }
        if (sum2>=10) {
            tBodyType.settYangQuality(0);
        }else {
            tBodyType.settYangQuality(1);
        }
        if(sum3>=10){
            tBodyType.settYinDeficiency(0);
        }else {
            tBodyType.settYinDeficiency(1);
        }
        tBodyType.settMemberId(id);
        Date today = new Date(System.currentTimeMillis());
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String date = simpleDateFormat.format(today);
        tBodyType.setCreatetime(date);
        int i = tj_tBodyTypeService.addType(tBodyType);
        return i;
    }
    //根据体质类型编号查询
    @GetMapping("/{id}")
    public TBodyType queryById(@PathVariable("id")Integer id){
        return tj_tBodyTypeService.queryById(id);
    }

    //根据会员编号和创建时间删除
    @DeleteMapping("/{id}/{createtime}")
    public int delType(@PathVariable("id")Integer id,@PathVariable("createtime") String createtime){
        int i = tj_tBodyTypeService.delType(id, createtime);
        return i;
    }
}
